package com.tcxhb.job.admin.controller;

import com.tcxhb.job.admin.model.request.LoginReq;
import com.tcxhb.job.admin.model.request.biz.JobLogReq;
import com.tcxhb.job.common.model.MiscResult;
import com.tcxhb.job.common.request.CommonIdQueryReq;
import com.tcxhb.job.core.entity.TokenDTO;
import com.tcxhb.job.core.service.ShellService;
import com.tcxhb.job.core.utils.Md5Utils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.SystemUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description:
 * @Auther: tcxhb
 * @Date: 2023/11/21
 */
@RestController
@RequestMapping("/job/log")
@Slf4j
public class JobLogController {
    @Autowired
    private ShellService service;

    @PostMapping(value = "/fetch")
    public MiscResult<List<String>> fetch(@RequestBody JobLogReq req) {
        // 实例ID
        String cmd = "cat /data/logs/best-job/log.log | grep " + req.getKey();
        if (SystemUtils.IS_OS_WINDOWS) {
            cmd = "ping www.baiud.com";
        }
        return service.command(cmd);
    }
}
